package org.dromara.common.model.enums.groupuser;

/**
 * 群聊邀请成员时的确认状态
 * @author Stars
 */
public enum GroupInvitationConfirmationEnum {
    NOT_REQUIRED(0, "未开启"),
    REQUIRED(1, "已开启");

    private final int code;
    private final String description;

    GroupInvitationConfirmationEnum(int code, String description) {
        this.code = code;
        this.description = description;
    }

    public int getCode() {
        return code;
    }

    public String getDescription() {
        return description;
    }

    /**
     * 根据群聊邀请确认状态代码获取对应的状态描述
     * @param code 群聊邀请确认状态代码
     * @return 对应的状态描述，如果未找到则返回 null
     */
    public static String getDescriptionByCode(int code) {
        for (GroupInvitationConfirmationEnum status : values()) {
            if (status.getCode() == code) {
                return status.getDescription();
            }
        }
        return null;
    }

    /**
     * 根据群聊邀请确认状态代码获取对应的枚举实例
     * @param code 群聊邀请确认状态代码
     * @return 对应的枚举实例，如果未找到则返回 null
     */
    public static GroupInvitationConfirmationEnum getByCode(int code) {
        for (GroupInvitationConfirmationEnum status : values()) {
            if (status.getCode() == code) {
                return status;
            }
        }
        return null;
    }
}
